package phoenix.web.page_objects.features;

import java.util.List;

import org.openqa.selenium.WebElement;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseWebExt;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.web.locators.base.GalleryPageLocatorsBase;

/**
 * Created by AlexGolovko on 26.11.2014.
 */
public class GalleryPage extends PageBaseWebExt
{
	/**
	 * Initializes PageBaseWebExt
	 * @param p_manager PhoenixManager instance
	 */
	public GalleryPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	public GalleryPageLocatorsBase elements()
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_CLICKANDFLIRT:
			{
				return new phoenix.web.locators.clickandflirt.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_LOCALSGOWILD:
			{
				return new phoenix.web.locators.localsgowild.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_EBONYFLIRT:
			{
				return new phoenix.web.locators.ebonyflirt.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_CHEECKYLOVERS:
			{
				return new phoenix.web.locators.cheekylovers.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.web.locators.wildbuddies.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.web.locators.flirt.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_FOREIGNGIRLFRIEND:
			{
				return new phoenix.web.locators.foreigngirlfriend.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_BENAUGHTY:
			{
				return new phoenix.web.locators.benaughty.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_NAUGHTYFEVER:
			{
				return new phoenix.web.locators.naughtyfever.GalleryPageLocators();
			}
			case ConfigExt.SITE_ID_MATUREDATING:
			{
				return new phoenix.web.locators.maturedating.GalleryPageLocators();
			}
			default:
			{
				return null;
			}
		}
	}

	/**
	 * Galley tests related
	 */
	public void clickUserPhoto()
	{
		log().info("Click at photo gallery");
		wd().waitForVisibility(elements().btnGallery, "Photo gallery");
		wd().click(elements().btnGallery);
	}

	public void clickCloseGallery()
	{
		log().info("Click close in gallery");
		wd().waitForVisibility(elements().btnClose, "Close gallery");
		wd().click(elements().btnClose);
	}

	public void clickAllPhotos()
	{
		log().info("Click All Photos in gallery");
		wd().waitForVisibility(elements().btnAllPhotos, "All photos button");
		wd().click(elements().btnAllPhotos);
	}

	public void clickNextPhoto()
	{
		log().info("Click next button in gallery");
		wd().waitForPresence(elements().btnNext, "Next button gallery");
		wd().click(elements().btnNext);
	}

	public void clickPrevPhoto()
	{
		log().info("Click Previous button in gallery");
		wd().waitForPresence(elements().btnPrevious, "Previous button gallery");
		wd().click(elements().btnPrevious);
	}

	private WebElement listOfPhotos()
	{
		return wd().driver().findElement(elements().elPhotoList);
	}

	public int getPhotoCount()
	{
		List<WebElement> el = this.listOfPhotos().findElements(elements().elPhotoItem);
		return el.size();
	}

	public void waitForPageLoad()
	{
		wd().waitForVisibility(elements().btnAllPhotos, "All photos btn");
	}

	public String getPhotoId()
	{
		return wd().getAttribute(elements().elActivePhoto, "data-gallery-photos");
	}
}
